﻿#region Copyright

// /*
// SilverlightInEnterprise
// SilverlightInEnterprise.SharedCode.Repository
// InventoryRecord.cs
// 
// Author: Matt Van Horn
// Created 11/17/2011 3:15 PM
// Copyright: Silverlight in the Enterprise www.slinenterprise.com
// 
// Licensed under MS-PL http://www.opensource.org/licenses/MS-PL and while you 
// may use this in anyway you see fit and owe us nothing to do so, we wouldn't mind knowing that you got value out of the work we did (so we will do more) so 
// we ask that you leave a comment on www.slinenterprise.com or on the codeplex site slinenterprise.codeplex.com
// 
// */

#endregion

using System;
using System.Runtime.Serialization;

namespace SilverlightInEnterprise.SharedCode.Repository.Models
{
    [Flags]
    public enum RecordAction : byte
    {
        BoughtFromSupplier = 1,
        SoldToClient = 2,
        DefectiveAndWaste = 4,
        Returns = 8
    }

    public enum EffectOnInventory : byte
    {
        Reduced = 6,
        Increased = 9
    }

    [DataContract]
    public partial class InventoryRecord
    {
        [DataMember]
        public int Id { get; set; }

        [DataMember]
        public int ProductId { get; set; }

        [DataMember]
        public int Units { get; set; }

        public RecordAction RecordTypeFlag
        {
            get { return (RecordAction) Enum.ToObject(typeof (RecordAction), this.RecordType); }
            set { this.RecordType = (byte) value; }
        }

        [DataMember]
        public byte RecordType { get; set; }

        public EffectOnInventory Effect
        {
            get
            {
                bool isIncrease = ((byte) this.RecordTypeFlag & (byte) EffectOnInventory.Increased) == this.RecordType;

                return isIncrease ? EffectOnInventory.Increased : EffectOnInventory.Reduced;
            }
        }

        public override bool Equals(object obj)
        {
            if (obj == null) return false;
            return this.Id == (obj as InventoryRecord).Id;
        }
    }
}